<template>
    <div class="main">
        <div class="applyforwithdrawal mg_tb12">
            <div class="withdrawalway mg_rl12">
                <a href="javascript:;" class="" @click="goWithdrawal">
                    <img src="../../static/imgs/bj_1.png" v-if="selWay.account_type == 1">
                    <!-- 微信提现下版上 -->
                    <!-- <img src="../../static/imgs/bj_2.png" v-if="selWay.account_type == 2"> -->
                    <img src="../../static/imgs/bj_3.png" v-if="selWay.account_type == 3">
                    <div class="withdrawal_list">
                        <div class="list_left clfff">
                            <p class="ft18" v-if="selWay.account_type == 1">支付宝</p> 
                            <!-- 微信提现下版上 -->
                            <!-- <p class="ft18" v-if="selWay.account_type == 2">微信</p>  -->
                            <p class="ft18" v-if="selWay.account_type == 3">银行卡</p>                             
                            <p class="ft12 " v-if="selWay.account_type == 1">
                                <span class="phone_begin">{{phone_begin}}</span>
                                <span class="hide_phone"></span>
                                <span class="phone_end">{{phone_end}}</span>
                            </p> 
                            <p class="ft12 " v-if="selWay.account_type == 3">
                                <span class="hide_phone2"></span>
                                <span class="hide_phone2"></span>
                                <span class="hide_phone2"></span>
                                <span class="phone_end">{{bankNumber}}</span>
                            </p>   
                            <!-- <p class="ft12" v-if="selWay.account_type == 2">{{selWay.account}}</p>    -->
                        </div>
                        <div class="list_right"  v-if="selWay.account_type != 2">
                        <i class="db go_withdrawal"></i>
                        </div>
                    </div>
                </a>
            </div>
            <div  class="operation mg_tb12">
                <Getverificationcode :cbfn="'codetrgget'" @codetrgget="getcodeVal" :width="54" :getcodeurl="getcodeurl" :phone="phone"></Getverificationcode>

            </div>
            <p class="note ft14 clb3 mg_rl12" style="margin-top: -2px">验证码将会下发至{{encryptPhone}}，
                <!-- <span v-if="selWay.account_type == 2">最低1元，</span> -->
                <span v-if="selWay.account_type == 3">最低50元，</span>每日提现最多10次</p>
            <Confimbtn :disablebtn="disablebtn" :copy="copy" @confimtrigger="confimSubimt" :cbfn="'confimtrigger'" ></Confimbtn>
        </div>

    </div>
    <!-- 组件的模板 -->
        
</template>

<script>
    /**
     *  引入工具类库 或 Native API
     *  example : import widget from 'gapi/widget'
     */

    import * as util from 'js/util.js'
    import widget from 'gapi/widget'
    import commonPage from 'clientApi/commonPage.js'    
    import clientInfo from 'gapi/clientInfo.js'
    import cache from 'gapi/cache.js'
    import safety from 'gapi/safety.js'
    import * as common from 'js/common.js'
    // import ApiClientUi from 'clientApi/ApiClientUi.js'
    /**
     *  引入组件 以及 组件接口(Action)
     *  example : import Somecomponents from 'components/Somecomponents/Somecomponents'
     */
    import Getverificationcode from 'components/Getverificationcode/Getverificationcode'
    import Confimbtn from 'components/Confimbtn/Confimbtn'

    /**
     *  组件实例对象
     */
    export default {
        components: {
            Getverificationcode,
            Confimbtn,
        },
        data: function(){
            return{
                disablebtn:true,
                copy:'确认提现',
                note:{
                    wechat:{
                        name:'微信',
                        time:'实时',
                        minMoney:1
                    },
                    bank:{
                        name:'银行卡',
                        time:'72小时',
                        minMoney:50
                    },
                    alipay:{
                        name:'支付宝',
                        time:'实时',
                        minMoney:1
                    }
                },
                moneymessage:'',
                way:'',
                allMoney:0,
                withdrawalMoney:'',
                withdrawalError:false,
                getcodeurl:'/wallet/mobile_code',
                selWay:{},
                code:'',
                valChange:'',
                phone:'',
                last_page: '',
                withdraw_errmsg: '',//提现提示信息
                withdraw_data: '',//提现信息
                balance: false,
                encryptPhone:'',//加密手机号
                phone_begin: '',
                phone_end: '',
                bankNumber:'',

            }
        },
        vuex: {
            getters: {

            },
            actions: {

            }
        },
        methods: {
            /**
             * 初始化
             * @return {Null} void
             */
            init (){
                this.last_page = util.getUrddataString('last_pageUrl');
                // alert(this.last_page)
                commonPage.loadPageStatus('loading')                
                util.ajax({
                    url:'/wallet/withdraw/mode_detail/get',
                    type:'GET',
                    data:{
                        account_type: this.last_page,
                    },
                    timeout:10000,
                    success:(data) => {
                        // alert(JSON.stringify(data))
                        commonPage.loadPageStatus('loadSuccess')
                        if(data.errno == 0){
                            this.selWay = data.data
                            this.phone = data.data.mobile
                            let phone = this.phone;
                            this.encryptPhone = phone.substr(0, 3) + '****' + phone.substr(7);
                            let money = parseInt(this.selWay.balance)
                            if(this.selWay.account_type == 1){
                                let account = this.selWay.account
                                this.phone_begin = account.substr(0, 3)
                                this.phone_end = account.substr(7)
                            }else if(this.selWay.account_type == 3){
                                let bankNumber = this.selWay.account;
                                this.bankNumber = bankNumber.substr(-4);
                            }
                           
                            if((this.selWay.account_type == 2 && this.selWay.balance >= 1) || (this.selWay.account_type == 1 && this.selWay.balance > 0) || (this.selWay.account_type == 3 && this.selWay.balance >= 50)){
                                this.balance = true
                            }else{
                                this.balance = false
                            }
                        }else{
                            widget.toast(data.errmsg)
                        }
                    },
                    error:function(status){
                        console.log(JSON.stringify(status))
                        commonPage.loadPageStatus('loadSuccess')
                        widget.toast('服务器异常')
                    }
                })
            },
            //申请提现
            confimSubimt(){
                commonPage.loadPageStatus('loading')
                this.disablebtn = true;
                util.ajax({
                    url:'/wallet/new_put_forward',
                    type:'POST',
                    data:{
                        account_type: this.last_page,
                        msg_code: this.code,
                        mobile: this.phone
                    },
                    timeout:10000,
                    success:(data) => {
                        commonPage.loadPageStatus('loadSuccess')
                        this.disablebtn = false
                        this.withdraw_errmsg = data.errmsg
                        this.withdraw_data = data.data?data.data:{}
                        let status 
                        if(data.errno == 25015){
                            widget.toast('短信验证码填写错误')
                            return
                        }else if(data.errno == 11000){
                            widget.toast('请求参数错误')
                            return
                        }else if(data.errno == 28010){
                            widget.toast('查询用户钱包余额出错，请重试')
                            return
                        }else if(data.errno == 0){
                            status = 1
                        }else{
                            status = 0
                        }
                        let encodeStr = encodeURIComponent(`errmsg=${this.withdraw_errmsg}&amount=${this.withdraw_data.amount}&account=${this.withdraw_data.account}&status=${status}&last_pageUrl=${this.last_page}`)
                        location.href = `dmsaas://WithdrawalStatus?urdData=${encodeStr}`  
                    },
                    error:function(status){
                        commonPage.loadPageStatus('loadSuccess')
                        this.disablebtn = false
                        widget.toast('服务器异常')
                    }
                })

            },
            getcodeVal(val){
                this.code = val;
            },
            goWithdrawal(){
                location.href = `dmsaas://WithdrawalWay`;
            }
        },
        computed:{
            valChange:function(){
                return '' + this.code;
            }
        },
        watch:{
            valChange:function(){
                if(this.code.length === 6 && this.balance){
                    this.disablebtn = false;
                }else{
                    this.disablebtn = true;
                }
            }
        },
        created(){
            
            this.init();
            commonPage.updateTitleBar({
                backAction: 'goBack',
                leftAction: 'goBack'
            })
            window.goBack = () => {
                // location.href = `dmsaas://MyWallet`;
                cache.getMemoryCache('yyMywalletWebViewID',function(data){
                    if(data){
                        commonPage.goBack(1, {}, data.webViewID)
                    }
                })
            }
            
        }
        
    }
</script>

<!-- CSS 样式 -->
<!-- <style src="static/css/global.css"></style> -->
<style src="../../node_modules/weui/dist/style/weui.css"></style>
<style src="../../static/css/base.css"></style>
<style src="../../static/css/yy_applyForWithdrawal.css"></style>


